﻿/*******************************************************************************
 * AAEngine
 * Copyright (c) 2010 Mike Jarosch
 *
 * This file is licensed under the terms of the MIT license, which is included
 * in the "MIT License.txt" file at the root directory of this SDK.
 ******************************************************************************/

using System.Xml.Linq;

namespace AAEngine.Engine.Core
{
    public static class XmlExtensions
    {
        public static string GetAttribute(this XElement @this, string name)
        {
            if (@this.Attribute(name) == null)
            {
                return "";
            }

            return @this.Attribute(name) == null ? "" : @this.Attribute(name).Value;
        }

        public static void SetAttribute(this XElement @this, string name, string value)
        {
            @this.SetAttributeValue(name, value);
        }

        public static void SetAttribute(this XElement @this, string name, int value)
        {
            @this.SetAttributeValue(name, value);
        }

        public static bool HasAttribute(this XElement @this, string name)
        {
            return @this.Attributes(name) != null;
        }

        public static XElement AddElement(this XElement @this, string name)
        {
            XElement element = new XElement(name);
            @this.Add(element);
            return element;
        }
    }
}
